1. Field of the Invention
This invention relates to a data processing apparatus and method for handling shift operations on a data value. More particularly, this invention relates to a data processing apparatus and method in which a data value is read from a register file, shifted, and stored back into the register file.
2. Description of the Prior Art
A barrel shifter is a circuit which is operable to shift a data value by a specified number of bit positions. This can be useful in a number of ways. For instance, a barrel shifter can be used to provide hardware support for fixed-point arithmetic, where an arithmetic shift n positions to the left is equivalent to multiplying by 2n, and an arithmetic shift n positions to the right is equivalent to dividing by 2n. In this way, a multiplication or division operation can be conducted within a single processor cycle. A barrel shifter is usually implemented as a series of multiplexer stages, with each multiplexer of a stage receiving as an input an output from two multiplexers of the preceding stage. It will be appreciated that a very large number of multiplexers are required in order to shift large data values by large shift amounts.
In one arrangement the barrel shifter can be provided in two logical blocks, the first block rotating the bit values through a small number of bit positions to provide a shift (in single bit increments) of up to (for example) one byte of a four byte data word by using the multiplexer arrangements described above, and the second block providing a function of permuting the four bytes of the data word into a different order to shift the data word in byte increments. Once the rotation and permutation operations have been conducted, any bit positions vacated by the shift operation can be masked to a desired value. For example, in the case of an n bit position arithmetic shift to the left, zeroes are set by the masking operation at the n least significant bits of the shifted data value, and in the case of an n bit position arithmetic shift to the right, the sign bit of the original data value is set at the n most significant bits of the shifted data value. Alternatively, in the case of an n bit position logical shift to the left or right, zeroes are set by the masking operation at the n least significant bit or most significant bits respectively of the shifted data value.
A register file is a set of registers typically provided in, or in association with, a processor such as a central processing unit (CPU). The register file temporarily stores data while it is being operated on by the processor. For example, data may be transferred from a memory to the register file when it is required to be operated on as part of a data processing operation, and data generated by such a data processing operation may be stored to the register file before either being transferred to the memory or used by a subsequent data processing operation. In the context of a shift operation, the barrel shifter retrieves data to be shifted from the register file, operates on the retrieved data word to shift it by a required number of bit positions, and stores the shifted data word back into the register file once the shift operation has been completed.
When a data value is to be loaded from memory into the register file, for a register file which stores four byte data words it is usually necessary to load four bytes of data from memory even if only a single one of those four bytes is actually required. As a result, the desired byte of data may be at any one of the four byte positions within the register. In order that the desired byte can be used, it is then aligned to the least significant byte position within the register (for a little endian memory system), and optionally sign extended to the entire register width. As will be appreciated, switching circuitry is required in order to perform these functions.